<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>创建实例对象发送请求</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
</head>
<body>
    <button>获取英雄</button>
    <button>获取段子</button>
    <script>
        //创建 axios 的实例对象
        let axios1 = axios.create({
            baseURL: 'http://api.xiaohigh.com:8090'
        });

        //获取元素
        let btns = document.querySelectorAll("button");
        //绑定事件
        btns[0].onclick = async function(){
            //发送请求
            // let result = await axios1.get('http://api.xiaohigh.com:8090/lol');
            let result = await axios1({url: '/lol?q=法师'})
            //查看响应体
            console.log(result.data);
        }
        
        // https://api.apiopen.top/getJoke
        let axios2 = axios.create({
            baseURL: 'https://api.apiopen.top'
        })

        btns[1].onclick = async function(){
            //获取段子
            let result = await axios2.get('/getJoke');
            console.log(result);
        }

    </script>
</body>
</html>